package com.lychee.demo.controller;

import java.util.List;

import com.lychee.common.core.annotation.Log;
import com.lychee.common.core.annotation.RepeatSubmit;
import com.lychee.common.core.base.BaseController;
import com.lychee.common.core.base.page.PageQuery;
import com.lychee.common.core.base.page.TableDataInfo;
import com.lychee.common.core.domain.JsonResult;
import com.lychee.common.core.enums.BusinessType;
import com.lychee.common.core.validate.AddGroup;
import com.lychee.common.core.validate.EditGroup;
import com.lychee.common.excel.utils.ExcelUtil;
import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.lychee.demo.domain.vo.TestMoreDemoVo;
import com.lychee.demo.domain.bo.TestMoreDemoBo;
import com.lychee.demo.service.ITestMoreDemoService;

/**
 * 测试表
 *
 * @author DingHao
 * @date 2025-08-14
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/demo/moreDemo")
public class TestMoreDemoController extends BaseController {

    private final ITestMoreDemoService testMoreDemoService;

    /**
     * 查询测试表列表
     */
    @SaCheckPermission("demo:moreDemo:list")
    @GetMapping("/list")
    public TableDataInfo<TestMoreDemoVo> list(TestMoreDemoBo bo, PageQuery pageQuery) {
        return testMoreDemoService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出测试表列表
     */
    @SaCheckPermission("demo:moreDemo:export")
    @Log(title = "测试表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(TestMoreDemoBo bo, HttpServletResponse response) {
        List<TestMoreDemoVo> list = testMoreDemoService.queryList(bo);
        ExcelUtil.exportExcel(list, "测试表", TestMoreDemoVo.class, response);
    }

    /**
     * 获取测试表详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("demo:moreDemo:query")
    @GetMapping("/{id}")
    public JsonResult<TestMoreDemoVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return JsonResult.ok(testMoreDemoService.queryById(id));
    }

    /**
     * 新增测试表
     */
    @SaCheckPermission("demo:moreDemo:add")
    @Log(title = "测试表", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public JsonResult<Void> add(@Validated(AddGroup.class) @RequestBody TestMoreDemoBo bo) {
        return toAjax(testMoreDemoService.insertByBo(bo));
    }

    /**
     * 修改测试表
     */
    @SaCheckPermission("demo:moreDemo:edit")
    @Log(title = "测试表", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public JsonResult<Void> edit(@Validated(EditGroup.class) @RequestBody TestMoreDemoBo bo) {
        return toAjax(testMoreDemoService.updateByBo(bo));
    }

    /**
     * 删除测试表
     *
     * @param ids 主键串
     */
    @SaCheckPermission("demo:moreDemo:remove")
    @Log(title = "测试表", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public JsonResult<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(testMoreDemoService.deleteWithValidByIds(List.of(ids), true));
    }
}
